package com.csc.dao;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;
import javax.transaction.Transactional;

import org.springframework.stereotype.Repository;

import com.csc.domain.SystemAccount;

import constants.Constant;

@Repository
public class LoginDAOImpl implements LoginDAO {
	@PersistenceContext
	EntityManager em;

	/**
	 * @author Nguyen Vu Hung
	 * 
	 */
	@Transactional
	public SystemAccount checkLogin(String userName, String password) {
		SystemAccount sysAccount = em.find(SystemAccount.class, userName);
		if (null != sysAccount
				&& sysAccount.getAccountPassword().equals(password))
			return sysAccount;
		return null;
	}

	// Nguyen Vu Hung - Get new account
	@Override
	public List<SystemAccount> getListAccountNew() {
		TypedQuery<SystemAccount> query = em.createQuery(
				"SELECT t FROM SystemAccount t WHERE t.systemStatus.statusId  = "
						+ Constant.STATUS_ID_NEW + "", SystemAccount.class);
		return query.getResultList();
	}
}
